<!--$Id: mod.so,v 10.6 2007/07/07 14:45:24 bostic Exp $-->
<!--Copyright (c) 1997,2008 Oracle.  All rights reserved.-->
<!--See the file LICENSE for redistribution information.-->
<html>
<head>
<title>Berkeley DB Reference Guide: Using Berkeley DB with Apache</title>
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++">
</head>
<body bgcolor=white>
<a name="2"><!--meow--></a><a name="3"><!--meow--></a>
<table width="100%"><tr valign=top>
<td><b><dl><dt>Berkeley DB Reference Guide:<dd>Berkeley DB Extensions</dl></b></td>
<td align=right><a href="../tcl/faq.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../ext/perl.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p align=center><b>Using Berkeley DB with Apache</b></p>
<p>A mod_db4 Apache module is included in the Berkeley DB distribution, providing
a safe framework for running Berkeley DB applications in an Apache 1.3
environment.  Apache natively provides no interface for communication
between threads or processes, so the mod_db4 module exists to provide
this communication.</p>
<p>In general, it is dangerous to run Berkeley DB in a multiprocess system
without some facility to coordinate database recovery between processes
sharing the database environment after application or system failure.
Failure to run recovery after failure can include process hangs and an
inability to access the database environment.  The mod_db4 Apache module
oversees the proper management of Berkeley DB database environment resources.
Developers building applications using Berkeley DB as the storage manager
within an Apache module should employ this technique for proper resource
management.</p>
<p>Specifically, mod_db4 provides the following facilities:</p>
<ol>
<p><li>New constructors for <a href="../../api_c/env_class.html">DB_ENV</a> and <a href="../../api_c/db_class.html">DB</a> handles, which install
replacement open/close methods.
<p><li>Transparent caching of open <a href="../../api_c/env_class.html">DB_ENV</a> and <a href="../../api_c/db_class.html">DB</a> handles.
<p><li>Reference counting on all structures, allowing the module to detect the
initial opening of any managed database and automatically perform recovery.
<p><li>Automatic detection of unexpected failures (segfaults, or a module
actually calling exit() and avoiding shut down phases), and automatic
termination of all child processes with open database resources to
attempt consistency.
</ol>
<p>mod_db4 is designed to be used as an alternative interface to Berkeley DB.  To
have another Apache module (for example, mod_foo) use mod_db4, do not
link mod_foo against the Berkeley DB library.  In your mod_foo makefile, you
should:</p>
<blockquote><pre>#include "mod_db4_export.h"</pre></blockquote>
<p>and add your Apache include directory to your CPPFLAGS.</p>
<p>In mod_foo, to create a mod_db4 managed <a href="../../api_c/env_class.html">DB_ENV</a> handle, use the
following:</p>
<blockquote><pre>int mod_db4_db_env_create(DB_ENV **dbenvp, u_int32_t flags);</pre></blockquote>
<p>which takes identical arguments to <a href="../../api_c/env_class.html">db_env_create</a>.</p>
<p>To create a mod_db4 managed <a href="../../api_c/db_class.html">DB</a> handle, use the following:</p>
<blockquote><pre>int mod_db4_db_create(DB **dbp, DB_ENV *dbenv, u_int32_t flags);</pre></blockquote>
<p>which takes identical arguments to <a href="../../api_c/db_class.html">db_create</a>.</p>
<p>Otherwise the API is completely consistent with the standard Berkeley DB
API.</p>
<p>The mod_db4 module requires the Berkeley DB library be compiled with C++
extensions and the MM library.  (The MM library provides an abstraction
layer which allows related processes to share data easily. On systems
where shared memory or other inter-process communication mechanisms are
not available, the MM library emulates them using temporary files. MM
is used in several operating systems to provide shared memory pools to
Apache modules.)</p>
<p>To build this apache module, perform the following steps:</p>
<blockquote><pre>% ./configure --with-apxs=[path to the apxs utility] \
	--with-db4=[Berkeley DB library installation directory] \
	--with-mm=[libmm installation directory]
% make
% make install</pre></blockquote>
<p>Post-installation, modules can use this extension via the functions
documented in $APACHE_INCLUDEDIR/mod_db4_export.h.</p>
<table width="100%"><tr><td><br></td><td align=right><a href="../tcl/faq.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../ext/perl.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p><font size=1>Copyright (c) 1996,2008 Oracle.  All rights reserved.</font>
</body>
</html>
